/*
 * Copyright 2011 Angel Sanadinov
 *
 * This file is part of VBox WMI.
 *
 * VBox WMI is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * VBox WMI is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
 */

package Beans.Requests.MediumManagement;

import Utilities.PermissionsConstants;
import org.virtualbox_3_2.DeviceType;

/**
 * Instances of this class are used by the user interface when a request to
 * remove a medium is sent to the media management service.
 *
 * @author Angel Sanadinov
 */
public class RemoveMediumRequest extends MediumManagementRequest
{
    private boolean deleteStorage; //denotes whether the base storage should be deleted
    private DeviceType deviceType; //the type of medium (device) being removed

    /**
     * No-argument constructor. <br><br>
     * All fields are set to their invalid values.
     */
    public RemoveMediumRequest()
    {
        setRequestedAction(PermissionsConstants.ACTION_MEDIUM_REMOVE);
        this.deleteStorage = false;
    }

    /**
     * Constructs a "remove medium" request with the specified data.
     *
     * @param requestorId the id of the user that made the request
     * @param serverId the id of the server on which the disk resides
     * @param mediumId the id of the disk
     * @param deviceType the type of device being removed
     * @param deleteStorage set to <code>true</code> if the base storage should
     *                      be removed from the host or to <code>false</code>
     *                      if it should be kept
     */
    public RemoveMediumRequest(int requestorId, int serverId, String mediumId, DeviceType deviceType, boolean deleteStorage)
    {
        setRequestedAction(PermissionsConstants.ACTION_MEDIUM_REMOVE);
        setRequestorId(requestorId);
        setServerId(serverId);
        setMediumId(mediumId);
        this.deleteStorage = deleteStorage;
        this.deviceType = deviceType;
    }

    /**
     * Returns whether the base storage should be removed from the host.
     *
     * @return <code>true</code> if the base storage is to be removed or <code>false</code>
     *         otherwise
     */
    public boolean getDeleteStorage()
    {
        return deleteStorage;
    }

    /**
     * Retrieves the type of device the medium represents.
     *
     * @return the medium device type
     */
    public DeviceType getDeviceType()
    {
        return deviceType;
    }

    /**
     * Sets the storage removal flag.
     *
     * @param deleteStorage set to <code>true</code> if the base storage should
     *                      be removed from the host or to <code>false</code>
     *                      if it should be kept
     */
    public void setDeleteStorage(boolean deleteStorage)
    {
        this.deleteStorage = deleteStorage;
    }

    /**
     * Sets the type of device the medium represents.
     *
     * @param device the medium device type
     */
    public void setDeviceType(DeviceType device)
    {
        this.deviceType = device;
    }

    @Override
    public boolean isValid()
    {
        if(super.isValid() && isMediumIdValid() && deviceType != null &&
                (deviceType == DeviceType.HARD_DISK || deviceType == DeviceType.DVD || deviceType == DeviceType.FLOPPY))
            return true;
        else
            return false;
    }

    /**
     * Returns a textual representation of the object. <br>
     *
     * It is in the form: "ClassName: (mediumId,deleteStorage,deviceType)".
     *
     * @return the object represented as a String
     */
    @Override
    public String toString()
    {
        return RemoveMediumRequest.class.getSimpleName() + ": (" + getMediumId()
                + "," + deleteStorage + "," + deviceType + ")";
    }
}
